import { ENUM_VIEW } from '../../../schema/constants';

/**
 * 获取数据地址
 * @type {String}
 */
export const GET_DATA_URL = ('/api/data');
export const GET_DATA_URL_SYMBOL = Symbol();

/**
 * 清除数据
 * @type {String}
 */
export const CLEAR_DATA = 'clear all data';

/**
 * 获取图表数据
 * @type {String}
 */
export const GET_DATA_REQUEST = 'get data by condition request';

/**
 * 查询成功
 * @type {String}
 */
export const GET_DATA_SUCCESS = 'get data by condition success';

/**
 * 查询失败
 * @type {String}
 */
export const GET_DATA_FAILURE = 'get data by condition failure';

/**
 * 清除数据
 * @return {String} Action描述
 */
export const clearData = () => ({ type: CLEAR_DATA });

/**
 * 获取数据
 * @param  {Integer of ENUM_VIEW} view 当前视图枚举值
 * @return {String}      Action描述
 */
export const getDataRequest = (view = ENUM_VIEW.NONE, chartName) => ({
	type: [ GET_DATA_REQUEST, GET_DATA_SUCCESS, GET_DATA_FAILURE ],
	payload: {
		view,
		[GET_DATA_URL_SYMBOL]: `${GET_DATA_URL}/${chartName}`
	}
});

/**
 * 获取成功
 * @param  {Object} data 获取回来的数据
 * @return {Object}      Action描述
 */
export const getDataSuccess = (data) => ({
	type: GET_DATA_SUCCESS,
	payload: { data }
});

/**
 * 获取失败
 * @return {[type]}       Action描述
 */
export const getDataFailure = () => ({
	type: GET_DATA_FAILURE,
});